package com.maimao.core.utils;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import com.maimao.core.constant.Constants;

import javax.crypto.SecretKey;
import java.io.UnsupportedEncodingException;

/**
 * @author MaoLin Wang
 * @date 2021/4/25 下午9:41
 */
public class SecurityUtil {
    /**
     * 隐藏手机中间5位
     *
     * @param mobile
     * @return
     */
    public static String fuzzMobile(String mobile) {
        if (StrUtil.isEmpty(mobile)) {
            return Constants.EMPTY;
        }
        if (!RegexUtils.checkMobile(mobile)) {
            return Constants.EMPTY;
        }
        return StrUtil.replace(mobile, 3, 7, Constants.STAR);
    }

    /**
     * 隐藏邮箱中间部分
     *
     * @param email 邮箱 如 823423432@qq.com
     * @return 返回  8*******2@qq.com
     */
    public static String fuzzEmail(String email) {
        if (StrUtil.isEmpty(email)) {
            return Constants.EMPTY;
        }
        if (!RegexUtils.checkEmail(email)) {
            return Constants.EMPTY;
        }
        return StrUtil.replace(email, 1, StrUtil.indexOf(email, Constants.AT) - 1, Constants.STAR);
    }
}
